package game;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Calendar;
import java.util.Date;

import sun.util.calendar.CalendarUtils;
import sun.util.resources.CalendarData_fr;

public class PlayerCommand implements KeyListener {

	private VisibleCharacter player;

	private Level level;

	private int delai = GameStandards.DELAY_BETWEEN_SHOOT;

//	private Date date;

	private int lastShoot = 0;

	public PlayerCommand(VisibleCharacter player, Level level) {
		this.player = player;
		this.level = level;
//		date = new Date();
	}

	public void keyPressed(KeyEvent arg0) {

		switch (arg0.getKeyCode()) {
		case KeyEvent.VK_UP: {
			if (player.getY() > 0)
				player.move(0, -10);
			break;
		}

		case KeyEvent.VK_DOWN: {
			if (player.getY() < GameStandards.FRAME_HEIGHT - player.getWidth())
				player.move(0, 10);
			break;
		}

		case KeyEvent.VK_LEFT: {
			if (player.getX() > 0)
				player.move(-10, 0);
			break;
		}

		case KeyEvent.VK_RIGHT: {
			if (player.getX() < GameStandards.FRAME_WIDTH - player.getWidth())
				player.move(10, 0);
			break;
		}

		case KeyEvent.VK_SPACE: {
			
			Date date = new Date();

			int seconde = (int) date.getTime() / 100;
			System.out.println(seconde + " " + lastShoot);

			if (Math.abs(Math.abs(lastShoot) - Math.abs(seconde)) < delai)
				break;
			else {

				System.out.println("secondes : " + date.getTime() / 1000);
				int playerX = player.getX();
				int playerY = player.getY();

				VisibleBullet bullet = new VisibleBullet(level.getGraphics(),
						playerX, playerY, true, this.level.getEnnemies());
				bullet.start();

				level.frame.repaint();
				lastShoot = seconde;
			}
		}

		}
	}

	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}

}
